<template>
	<view class="content">
		<view class="list" v-for="item in list" :key="item.id" @click="godetail(item)">
			<view class="img">
				<image :src="item.image" mode="aspectFit"></image>
			</view>
			<view class="right">
				<view class="title">{{item.goodsName}}</view>
				<view class="flex">
					<view class="jifen">
						<text>{{item.goodsPoint}}</text>积分
					</view>
					<image src="../../../static/img/rightarrow.png" class="rightarrow"></image>
				</view>
				<view class="date">{{item.createdTime}}</view>
			</view>
		</view>
		<view class="pagination" v-if="pagination">
			<view class="left" :class="{ forbid: paging.page == 1 }" @click="prev">
				<uni-icons type="arrowleft" size="20" color="#fff" class="icons" />
				上一页
			</view>
			<view class="center">{{ paging.page }}/{{ paging.total }}</view>
			<view class="right" :class="{ forbid: paging.page == paging.total }" @click="next">
				下一页
				<uni-icons type="arrowright" size="20" color="#fff" class="icons" />
			</view>
		</view>
		<view v-if="list.length==0" class="notavailable">
			<image src="../../../static/img/notavailable.png" mode="widthFix"></image>
			<view class="nottext">暂时没有数据</view>
		</view>
	</view>
</template>

<script>
	import integral from '../../../servers/integral/integral.js';
	export default {
		data() {
			return {
				list:[],
				pagination:true,
				paging: {
					page: 1,
					total: 100
				},
			}
		},
		onLoad() {

		},
		mounted(){
			this.initData();
		},
		methods: {
			initData(){
				var obj={
					currentPage: this.paging.page,
					pageSize: 10
				}
				integral.list(obj)
					.then(res => {
						if(res.code==200){
							if(res.data.records.length>0){
								this.paging.total = Math.ceil(res.data.total / res.data.size);
								this.list = res.data.records.map(v => {
									
									v.image = this.imgCDNUrl + v.goodsImg
									
									return v;
								});
								this.pagination=true
							}else{
								this.pagination=false
							}
							
							
						}else{
							uni.showToast({
								title:res.msg,
								icon:'none'
							})
						}
						
					})
					.catch(err => {
						
						console.log(new Error('请检查网络后重试'));
					});
			},
			godetail(item){
				uni.navigateTo({
					url:'./orderdetail?detail='+JSON.stringify(item)
				})
			},
			next() {
				if (this.paging.page < this.paging.total) {
					this.paging.page += 1;
					this.initData();
				}
			},
			prev() {
				if (this.paging.page > 1) {
					this.paging.page -= 1;
					this.initData();
				}
			}
		}
	}
</script>

<style scoped lang="scss" rel="stylesheet/scss">
	.content{
		padding: 0 20rpx;
	}
	.list{
		padding: 30rpx 0rpx;
		display: flex;
		border-bottom: 1px solid #e1e1e1;
		.img{
			border:1px solid #e1e1e1;
			border-radius: 12rpx;		
			width: 194rpx;
			height: 182rpx;
			margin-right: 20rpx;
			image{
				width: 100%;
				height: 100%;
			}
		}
		.right{
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			flex: auto;
			.title{
				font-size: 28rpx;
				color: #000;
			}
			.date{
				font-size: 26rpx;
				color: #999;
			}
			.flex{
				display: flex;
				align-items: center;
				justify-content: space-between;
				.jifen{
					font-size: 24rpx;
					color: #999;
					text{
						font-size: 36rpx;
						color: #f70225;
						margin-right: 20rpx;
						vertical-align: sub;
					}
				}
				image{
					width: 18rpx;
					height: 34rpx;
				}
			}
		
		}
		
	}
</style>
